# !/usr/bin/env python
# -*- coding: utf-8 -*-


import os

from dotenv import load_dotenv, find_dotenv
from starlette.datastructures import CommaSeparatedStrings, Secret
from databases import DatabaseURL

API_V1_STR = "/api/v1"

# jwt
JWT_TOKEN_PREFIX = "Token"
ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 7  # one week
ALGORITHM = "HS256"
# JWT 加密 密匙
SECRET_KEY = Secret(os.getenv("SECRET_KEY", "secret key for project"))

load_dotenv(find_dotenv())

# 信用中国数据库 credit_china
DATABASE_URL_WXMAP = os.getenv("POSTGRES_DB_WXMAP", "")  # deploying without docker-compose
if not DATABASE_URL_WXMAP:
    POSTGRES_HOST = os.getenv("POSTGRES_HOST_WXMAP", "localhost")
    POSTGRES_PORT = int(os.getenv("POSTGRES_PORT_WXMAP", 5432))
    POSTGRES_USER = os.getenv("POSTGRES_USER_WXMAP", "postgres")
    POSTGRES_PASS = os.getenv("POSTGRES_PASSWORD_WXMAP", "postgres")
    POSTGRES_NAME = os.getenv("POSTGRES_DB_WXMAP", "credit_china")

    DATABASE_URL_WXMAP = DatabaseURL(
        f"postgresql://{POSTGRES_USER}:{POSTGRES_PASS}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_NAME}"
    )
else:
    DATABASE_URL_CC = DatabaseURL(DATABASE_URL_WXMAP)

# 项目名称
PROJECT_NAME = os.getenv("PROJECT_NAME", "FastAPI example application")

# CORS允许的域名，不设置就默认为全部
ALLOWED_HOSTS = CommaSeparatedStrings(os.getenv("ALLOWED_HOSTS", ""))

# redis
REDIS_URL = os.getenv("REDIS_URL", "redis://127.0.0.1:6379")
